package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.pojo.Checkgroup;
import com.itheima.service.SetmealGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.SetmealGroupMapper;
import com.itheima.pojo.SetmealGroup;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class SetmealGroupServiceImpl extends ServiceImpl<SetmealGroupMapper, SetmealGroup> implements SetmealGroupService {
    @Autowired
    private SetmealGroupService setmealGroupService;
    @Autowired
    private SetmealGroupMapper setmealGroupMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public Long[] findGroupBySid(Long id) {
        return setmealGroupMapper.findGroupBySid(id);
    }

    @Override
    public Long[] findSetmealByCid(Long cid) {
        return baseMapper.findSetmealByCid(cid);
    }

    @Override
    public Long[] findSetmealByGid(Long gid){
        return setmealGroupMapper.findSetmealByGid(gid);
    }

    @Override
    public void addByCheckGroupIds(Long[] checkGroupIds,Long setmealId) {
        QueryWrapper<SetmealGroup> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("setmeal_id",setmealId);
        setmealGroupService.remove(queryWrapper);
        List<SetmealGroup> list = new ArrayList<>();
        for (Long checkGroupId : checkGroupIds) {
            SetmealGroup setmealGroup = new SetmealGroup();
            setmealGroup.setGroupId(checkGroupId);
            setmealGroup.setSetmealId(setmealId);
            list.add(setmealGroup);
        }
        setmealGroupService.saveBatch(list);
    }
}